package com.craney.testLoader
{
	import com.craney.testEvent.MyEvent;
	
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	
	public class TestLoader
	{
		private var parentSprite:Sprite;
		
		private var loader:Loader = new Loader();
		
		private var urlRequest:URLRequest = new URLRequest("dog.jpg");
		
		public function TestLoader(ps:Sprite)
		{
			parentSprite = ps;
			
			loader.load(urlRequest);
			
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, completeHandler);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(ev:Event):void{trace("haha");});
			
			parentSprite.addChild(loader);
			
		}



		private function completeHandler(event:Event):void
		{
			trace(event.target);
			trace(loader.numChildren);
			var my:MyDispatcher = new MyDispatcher();
			parentSprite.addChild(my);
			my.dispatchEvent(new MyEvent());
			trace("sent!");
		}
		
		public function eventHandler(event:Event):void
		{
			trace("OK");
		}
		
	}
}